package com.lwb.ztx.database;


import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;

/**
 * Created by luweibin on 2015/9/14.
 */
public class DBCreator {
    /**
     * 设置数据库的版本号，每次修改数据库表必须将版本号加1，然后run main方法生成对应的数据库
     */
    public static int DB_VERSION = 2;

    public static void main(String[] args) {
        // GreenDao设置
        Schema schema = new Schema(DB_VERSION, "com.lwb.ztx.database.greendao.db");
        schema.setDefaultJavaPackageTest("com.lwb.ztx.database.greendao.test");
        schema.setDefaultJavaPackageDao("com.lwb.ztx.database.greendao.dao");
        addCollect(schema);
        addLive(schema);
        try {
            new DaoGenerator().generateAll(schema, "./app/src/main/java");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void addCollect(Schema schema) {
        Entity collect = schema.addEntity("Collect");     // 设置表名
        collect.addStringProperty("collectDocId").primaryKey();
        collect.addStringProperty("collectType");
        collect.addStringProperty("collectImageUrl");
        collect.addStringProperty("collectLinkUrl");
        collect.addStringProperty("collectTitle");
        collect.addStringProperty("collectUpdateTime");
        collect.addStringProperty("collectSource");
        collect.addDateProperty("collectTime");
    }

    private static void addLive(Schema schema) {
        Entity live = schema.addEntity("Live");     // 设置表名
        live.addStringProperty("liveName").primaryKey();
        live.addStringProperty("livePath");
        live.addStringProperty("res");
    }

}
